OneStopTesting - Quality Testing Jobs, eBooks, Articles, FAQs, Training Institutes, Testing Software, Testing downloads, testing news, testing tools, learn testing, manual testing, automated testing, load runner, winrunner, test director, silk test, STLC

Forum| Contact Us| Testimonials| Sitemap| Employee Referrals| News| Articles| Feedback| Enquiry
 
Testing Resources
 
  • Testing Articles
  • Testing Books
  • Testing Certification
  • Testing FAQs
  • Testing Downloads
  • Testing Interview Questions
  • Career In Software Testing
  • Testing Jobs
  • Testing Job Consultants
  • Testing News
  • Testing Training Institutes
  •  
    Fundamentals
     
  • Introduction
  • Designing Test Cases
  • Developing Test Cases
  • Writing Test Cases
  • Test Case Templates
  • Purpose
  • What Is a Good Test Case?
  • Test Specifications
  • UML
  • Scenario Testing
  • Test Script
  • Test Summary Report
  • Test Data
  • Defect Tracking
  •  
    Software testing
     
  • Testing Forum
  • Introduction
  • Testing Start Process
  • Testing Stop Process
  • Testing Strategy
  • Risk Analysis
  • Software Listings
  • Test Metrics
  • Release Life Cycle
  • Interoperability Testing
  • Extreme Programming
  • Cyclomatic Complexity
  • Equivalence Partitioning
  • Error Guessing
  • Boundary Value Analysis
  • Traceability Matrix
  •  
    SDLC Models
     
  • Introduction
  • Waterfall Model
  • Iterative Model
  • V-Model
  • Spiral Model
  • Big Bang Model
  • RAD Model
  • Prototyping Model
  •  
    Software Testing Types
     
  • Static Testing
  • Dynamic Testing
  • Blackbox Testing
  • Whitebox Testing
  • Unit Testing
  • Requirements Testing
  • Regression Testing
  • Error Handling Testing
  • Manual support Testing
  • Intersystem Testing
  • Control Testing
  • Parallel Testing
  • Volume Testing
  • Stress Testing
  • Performance Testing
  • Agile Testing
  • Localization Testing
  • Globalization Testing
  • Internationalization Testing
  •  
    Test Plan
     
  • Introduction
  • Test Plan Development
  • Test Plan Template
  • Regional Differences
  • Criticism
  • Hardware Development
  • IEEE 829-1998
  • Testing Without a TestPlan
  •  
    Code Coverage
     
  • Introduction
  • Measures
  • Working
  • Statement Coverage
  • Branch Coverage
  • Path Coverage
  • Coverage criteria
  • Code coverage in practice
  • Tools
  • Features
  •  
    Quality Management
     
  • Introduction
  • Components
  • Capability Maturity Model
  • CMMI
  • Six Sigma
  •  
    Project Management
     
  • Introduction
  • PM Activities
  • Project Control Variables
  • PM Methodology
  • PM Phases
  • PM Templates
  • Agile PM
  •  
    Automated Testing Tools
     
  • Quick Test Professional
  • WinRunner
  • LoadRunner
  • Test Director
  • Silk Test
  • Test Partner
  • Rational Robot
  •  
    Performance Testing Tools
     
  • Apache JMeter
  • Rational Performance Tester
  • LoadRunner
  • NeoLoad
  • WAPT
  • WebLOAD
  • Loadster
  • OpenSTA
  • LoadUI
  • Appvance
  • Loadstorm
  • LoadImpact
  • QEngine
  • Httperf
  • CloudTest
  •  
    Languages
     
  • Perl Testing
  • Python Testing
  • JUnit Testing
  • Unix Shell Scripting
  •  
    Automation Framework
     
  • Introduction
  • Keyword-driven Testing
  • Data-driven Testing
  •  
    Configuration Management
     
  • History
  • What is CM?
  • Meaning of CM
  • Graphically Representation
  • Traditional CM
  • CM Activities
  • Tools
  •  
    Articles
     
  • What Is Software Testing?
  • Effective Defect Reports
  • Software Security
  • Tracking Defects
  • Bug Report
  • Web Testing
  • Exploratory Testing
  • Good Test Case
  • Write a Test
  • Code Coverage
  • WinRunner vs. QuickTest
  • Web Testing Tools
  • Automated Testing
  • Testing Estimation Process
  • Quality Assurance
  • The Interview Guide
  • Upgrade Path Testing
  • Priority and Severity of Bug
  • Three Questions About Bug
  •    
     
    Home » Testing Articles » Testing - General Articles » Script test in TestComplete

    Script test in TestComplete

    A D V E R T I S E M E N T


    In the last post, we learned how to create a keyword test in TestComplete. I had mentioned then that Script tests are more suitable for people who know a scripting language like VBScript or JScript and who have written test automation before. In this post, let us see how to build a script test to test the Windows Calculator. We will use data parametrization, external data sources, conditional statements and loops. Rest assured that it will not be simple at all.

    First, you open TestComplete on your Windows machine. Create a new project using the File | New | New Project... menu item. A wizard starts. Specify the Tested Application Type as Generic Windows Application. Select the scripting language as VBScript. Select Finish. You should have a new project open.

    Next, you add the Windows Calculator to the TestedApps folder as shown below. If you add an application to the tested apps, it will be available for launch during the record process from the TestComplete floating toolbar.


    Now, click the Record button. TestComplete minimizes to a toolbar. In the toolbar, click the Show Additional Buttons arrow. Then click the Run Tested Application button and select Calculator. In the Calculator, click all digit buttons, 0 to 9 and operator buttons, +, -, * and / and close the application. A keyword test is generated. Right-click on the keyword test and click Convert to Script... Give the script name as TestCalc. TestComplete generates the script test for you.

    We will re-use only a few auto-generated statements from the default script test. However, the good thing that TestComplete does is to automatically create name mapping Aliases for you that you can reference in your own code easily. Double-click NameMapping item in Project Explorer to see the window below.

    Next, we need to create the test data. This test consists of two operands that are the numbers which will be operated. The test data also consists of the operator that is the operation that will be performed on the two operands. Finally, the test data includes the expected result. Copy the below test data and paste it into a .csv file.

    operand1,operator,operand2,result
    2,add,3,5
    4,subtract,2,2
    5,multiply,6,30
    100,divide,5,20
    123,add,200,323
    50,add,30,80
    20,subtract,40,-20
    51,multiply,4,204
    10,divide,2,5
    2,add,13,15

    Let us write the Main routine of the script test. This routine is run when the script test is run. It launches the Calculator application, opens the .csv file, calls the VerifyResults routine for each row of the test data and finally closes the application. Notice that the back-slashes are escaped in the .csv file path. Copy the code below and paste into TestCalc script test. Note: all source code is in italics font.

    Dim wndCalculator

    Sub Main
    TestedApps.calc.Run
    Set wndCalculator = Aliases.calc.wndCalculator
    Dim page32770
    Set page32770 = wndCalculator.CalcFrame.page32770
    DDT.CSVDriver("E:\\Calculation.csv")
    'runs the VerifyResults routine for each row in the csv file
    DDT.CurrentDriver.DriveMethod("TestCalc.VerifyResults")
    wndCalculator.Close
    End Sub


    Before writing the VerifyResults routine, we need a routine to click the digit buttons in the Calculator application. Note that the button name suffixes in  the application are different from the respective digits. Copy the code below and paste it below the other code.

    Sub PerformClick(operand) 
    'Perform the click in the calculator application
    Dim panel
    Set panel = wndCalculator.CalcFrame.page32770
    Select Case operand
    Case "0"
    panel.btn6.ClickButton

    Case "1"
    panel.btn4.ClickButton

    Case "2"
    panel.btn.ClickButton        
    Case "3"
    panel.btn2.ClickButton        
    Case "4"
    panel.btn7.ClickButton        
    Case "5"
    panel.btn8.ClickButton        
    Case "6"
    panel.btn9.ClickButton        
    Case "7"
    panel.btn10.ClickButton        
    Case "8"
    panel.btn11.ClickButton        
    Case "9"
    panel.btn12.ClickButton        
    End Select 
    End Sub


    VerifyResults is the most important routine of this script test. Firstly, it reads the operand 1, operator, operand 2 and expected result values from a row of the .csv file. Next, it calls the PerformClick routine for each digit of the operand. The operand can be a single digit or multi-digit number. Therefore, PerformClick has to be called for each digit of the operand. Then, it clicks the button corresponding to the operator. Then it clicks the button(s) for operand 2. I was not able to get TestComplete to identify the object/ property pair that shows the result in the Calculator. Therefore, I copy the Calculator result to the clipboard and use it as the actual result. Copy the code below and paste it under existing code in the script test.

    Sub VerifyResults

    'Read the individual operand, operator and result values from the csv file
    Dim operand1, operand2, operator, expectedResult, actualResult
    operand1 = DDT.CurrentDriver.Value("operand1")
    operator = DDT.CurrentDriver.Value("operator")
    operand2 = DDT.CurrentDriver.Value("operand2")
    expectedResult = DDT.CurrentDriver.Value("result")
    Dim logString
    logString = operand1 & " "& operator & " " & operand2 & " :The expected result is " & expectedResult & " and the app returns "

    Dim count

    'Click the buttons for each digit of operand 1

    For  count = 1 To len(operand1)
    Call PerformClick(left(operand1,1))
    If len(operand1)>1 Then operand1=Mid(operand1,2 ,len(operand1)-1)
    Next

    'Click the button for the operator
    Dim panel
    Set panel = wndCalculator.CalcFrame.page32770

    Select Case operator
    Case "add"
    panel.btn5.ClickButton '+
    Case "subtract"
    panel.btn13.ClickButton '-
    Case "multiply"
    panel.btn1.ClickButton '*
    Case "divide"
    panel.btn14.ClickButton '/
    End Select

    'Click the buttons for each digit of operand 2
    For  count = 1 To len(operand2)
    Call PerformClick(left(operand2,1))
    If len(operand2)>1 Then operand2=Mid(operand2,2 ,len(operand2)-1)
    Next

    'Click the equals button
    panel.btn3.ClickButton '=
    Sleep (1000)

    'Get the result in the app
    Call wndCalculator.MainMenu.Click("Edit|Copy")
    actualResult = Sys.Clipboard
    logString = logString & actualResult
    If StrComp(expectedResult, actualResult, vbTextCompare) = 0 Then
      logString = logString & " that matches."
    Else
      logString = logString & " that does not match."
    End If

    Log.Message logString
    End Sub


    Now, you should be ready to run the script test. Right-click on the script test and click Run and then Run Main routine. You should get the a script test log similar to the one below. Notice that the Event check box is unchecked to de-clutter the test log.



    More Testing - General Articles
    1 2 3 4 5 6 7 8 9 10 11 Next



    discussionDiscussion Center
    Discuss
    Discuss

    Query

    Feedback
    Yahoo Groups
    Y! Group
    Sirfdosti Groups
    Sirfdosti
    Contact Us
    Contact

    Looking for Software Testing eBooks and Interview Questions? Join now and get it FREE!
     
    A D V E R T I S E M E N T
       
       

    Members Login


    Email ID:
    Password:


    Forgot Password
    New User
       
       
    Testing Interview Questions
  • General Testing
  • Automation Testing
  • Manual Testing
  • Software Development Life Cycle
  • Software Testing Life Cycle
  • Testing Models
  • Automated Testing Tools
  • Silk Test
  • Win Runner
  •    
       
    Testing Highlights

  • Software Testing Ebooks
  • Testing Jobs
  • Testing Frequently Asked Questions
  • Testing News
  • Testing Interview Questions
  • Testing Jobs
  • Testing Companies
  • Testing Job Consultants
  • ISTQB Certification Questions
  •    
       
    Interview Questions

  • WinRunner
  • LoadRunner
  • SilkTest
  • TestDirector
  • General Testing Questions
  •    
       
    Resources

  • Testing Forum
  • Downloads
  • E-Books
  • Testing Jobs
  • Testing Interview Questions
  • Testing Tools Questions
  • Testing Jobs
  • A-Z Knowledge
  •    
    Planning
    for
    Study ABROAD ?


    Study Abroad


    Vyom Network : Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Programming & Source Codes | Free eBooks | Job Interview Questions | Free Tutorials | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Bangalore Info | GATE Preparation | MBA Preparation | Free SAP Training
    Privacy Policy | Terms and Conditions
    Sitemap | Sitemap (XML)
    Job Interview Questions | Placement Papers | SMS Jokes | C++ Interview Questions | C Interview Questions | Web Hosting
    German | French | Portugese | Italian